//: Playground - noun: a place where people can play

import UIKit

/**
 属性将值跟特定的类、结构或枚举关联。存储属性存储常量或变量作为实例的一部分，而计算属性计算（不是存储）一个值。计算属性可以用于类、结构体和枚举，存储属性只能用于类和结构体
 */
struct FixIntRange {
    var start: Int
    let length: Int
}
var fixIntRange = FixIntRange(start: 1, length:3)
print("fixIntRange = \(fixIntRange)")

//修改start
fixIntRange.start = 5
/// length是常量，无法修改
//      fixIntRange.length = 5
print("fixIntRange = \(fixIntRange)")

/// 值属性
struct Point {
    var x = 0.0, y = 0.0
}
struct Size {
    var width = 0.0, height = 0.0
}
struct Rect {
    var origin = Point()
    var size = Size()
    var center : Point {
        get {
            let x = origin.x + (size.width / 2)
            let y = origin.y + (size.height / 2)
            return Point(x: x, y: y)
        }
        set(newCenter) {
            origin.x = newCenter.x - (size.width / 2)
            origin.y = newCenter.y - (size.height / 2)
        }
    }
}
var rect = Rect(origin: Point(x: 20, y:20), size: Size(width: 100, height:100))
let instanceCenter = rect.center
print("instanceCenter1: \(instanceCenter)")
rect.center = Point(x: 300, y:300)
print("instanceCenter2: \(instanceCenter)")
print("instanceCenter3: \(rect.center)")
